
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
<button id="btn">GET请求</button>
</body>
<script>
    var btn  = document.getElementById("btn");
    btn.onclick = sendMessage();
    function sendMessage() {
        var xhr = new XMLHttpRequest();
        // xhr.onreadystatechange = function () {
        //     undefined
        //     if (xhr.readyState === 4) {
        //         undefined
        //         if (xhr.status === 200) {
        //             完成且成功
        //         } else {
        //             完成但失败
        //         }
        //     }
        // }
        xhr.open("GET", "http://127.0.0.1:3000/register", true);
        xhr.setRequestHeader("Content-type", "application/json"); 
        // xhr.setRequestHeader("Content-type", "application/json"); 
          console.log(111);
        xhr.send({name: "张三"});
    }
</script>

</html>